package com.gmail.dmitryustimov.ms.java7.composite.classic.example;

import java.util.ArrayList;
import java.util.List;

/**
 * Composite
 * Author: Dmitry Ustimov
 * Date: 5/11/13
 * Time: 5:08 PM
 */
class CompositeGraphic extends Graphic {

    public CompositeGraphic(String name) {
        this.name = name;
    }

    //Collection of child graphics.
    private List<Graphic> childGraphics = new ArrayList<Graphic>();

    //Prints the graphic.
    public void print() {
        System.out.println("CompositeGraphic: " + name);
        for (Graphic graphic : childGraphics) {
            graphic.print();
        }
    }

    //Adds the graphic to the composition.
    public void add(Graphic graphic) {
        childGraphics.add(graphic);
    }

    //Removes the graphic from the composition.
    public void remove(Graphic graphic) {
        childGraphics.remove(graphic);
    }
}
